/*
 * Copyright (c) 2008-2012
 * LANIT
 * All rights reserved.
 *
 * This product and related documentation are protected by copyright and
 * distributed under licenses restricting its use, copying, distribution, and
 * decompilation. No part of this product or related documentation may be
 * reproduced in any form by any means without prior written authorization of
 * LANIT and its licensors, if any.
 *
 * $Id$
 */
package ru.lanit.bpm.ipa.timesheet;

import org.apache.commons.io.IOUtils;
import org.springframework.util.StringUtils;

import java.io.Reader;
import java.util.*;

/**
 * todo Document type PrepareRequisitesEmployee
 */
public class PrepareRequisitesEmployee {

    private Reader reader;

    public PrepareRequisitesEmployee(Reader reader) {
        this.reader = reader;
    }

    public Reader getReader() {
        return reader;
    }

    public void setReader(Reader reader) {
        this.reader = reader;
    }

    public Map<String, Collection<String>> getRequisites() {
        final int NAME_RU = 0;
        final int EMAIL = 2;
        // mail
        // pyUserIdentifier

        Iterator<String> iterator;
        Map<String, Collection<String>> requisites;
        Collection<String> details;
        requisites = new HashMap<String, Collection<String>>();

        iterator = IOUtils.lineIterator(reader);

        while (iterator.hasNext()) {

            String[] line = StringUtils.delimitedListToStringArray(iterator.next(), ";");

            String name = line[NAME_RU];
            details = new ArrayList<String>();
            String mail = line[EMAIL];
            details.add(mail);
            String[] tempString = mail.split("@");
            String pyUserIdentifier = tempString[0];
            details.add(pyUserIdentifier);
            requisites.put(name, details);

        }

        return requisites;
    }
}
